package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类品牌中间表 前端控制器
 *
 * @author atguigu
 * @since 2023-08-30
 */
@Api(tags = "分类品牌中间表控制器")
@RestController
@RequestMapping("/admin/product") //TODO 填写基础映射URL
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;


    /**
     * 根据category3Id获取品牌列表
     *
     * @param category3Id
     * @return
     */
    @ApiOperation("根据category3Id获取品牌列表")
    @GetMapping("/baseCategoryTrademark/findTrademarkList/{category3Id}")
    public Result getTrademarkList(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> list = baseCategoryTrademarkService.getTrademarkList(category3Id);
        return Result.ok(list);
    }


    /**
     * 根据category3Id获取可选品牌列表(未关联到分类品牌列表)
     *
     * @param category3Id
     * @return
     */
    @ApiOperation("根据category3Id获取可选品牌列表")
    @GetMapping("/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}")
    public Result getCurrentTrademarkList(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> list = baseCategoryTrademarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(list);
    }


    /**
     * 将多个品牌关联到分类
     *
     * @param vo
     * @return
     */
    @ApiOperation("将多个品牌关联到分类")
    @PostMapping("/baseCategoryTrademark/save")
    public Result saveCategoryTradeMark(@RequestBody CategoryTrademarkVo vo) {
        baseCategoryTrademarkService.saveCategoryTradeMark(vo);
        return Result.ok();
    }


    /**
     * 解除品牌关联分类
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @ApiOperation("解除品牌关联分类")
    @DeleteMapping("/baseCategoryTrademark/remove/{category3Id}/{trademarkId}")
    public Result deleteTIdFromCategory(@PathVariable("category3Id") Long category3Id, @PathVariable("trademarkId") Long trademarkId) {
        baseCategoryTrademarkService.deleteTIdFromCategory(category3Id, trademarkId);
        return Result.ok();
    }
}
